package com.wk.springboot.springbootproject.controller;

import com.wk.springboot.springbootproject.constant.KafkaConsts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class KafkaSend {


    @Autowired(required = false)
    private KafkaTemplate<String, String> kafkaTemplate;

    // 发送消息
    @GetMapping("/kafka/send")
    public void sendMessage1() {
        System.out.println("消费者发送消息");
        kafkaTemplate.send(KafkaConsts.TOPIC_TEST, "hello,kafka...");

    }
}